home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume2 / fonts / fastext3.1 next >
Internet Message Format  |  1988-11-10  |  32KB

  1. Path: xanth!nic.MR.NET!umn-d-ub!rutgers!mit-eddie!bbn!ulowell!page
  2. From: page@swan.ulowell.edu (Bob Page)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v02i059:  fasttext - speed up your text V3.0
  5. Message-ID: <10121@swan.ulowell.edu>
  6. Date: 10 Nov 88 02:34:25 GMT
  7. Organization: University of Lowell, Computer Science Dept.
  8. Lines: 924
  9. Approved: page@swan.ulowell.edu
  10.  
  11. Submitted-by: page@swan.ulowell.edu (Bob Page)
  12. Posting-number: Volume 2, Issue 59
  13. Archive-name: fonts/fasttext30.1
  14.  
  15. These routines utilize the blitter to speed up rendering of fonts of
  16. any height, and of 4-16 pixels in width.  Other fast text rendering
  17. routines only speed up rendering of 8 bit wide fonts.  This code can
  18. be linked in with your programs.  A skinny font is included so you
  19. can have more columns in a window.
  20.  
  21. [I lost the original submitter's address, sorry.  ..Bob]
  22.  
  23. #    This is a shell archive.
  24. #    Remove everything above and including the cut line.
  25. #    Then run the rest of the file through sh.
  26. #----cut here-----cut here-----cut here-----cut here----#
  27. #!/bin/sh
  28. # shar:    Shell Archiver
  29. #    Run the following text with /bin/sh to create:
  30. #    README
  31. #    Announcement
  32. #    8.uu
  33. #    wide.font.uu
  34. #    FastText.asm
  35. #    FastText.doc
  36. #    Ftest.c
  37. # This archive created: Wed Nov  9 21:22:54 1988
  38. cat << \SHAR_EOF > README
  39. FastText Copyright 1988 by Darren M. Greenwald
  40.  
  41. This is the first revision of my new FastText() code which
  42. can be linked in, and included within your programs.  These
  43. new routines utilize the blitter, and speed up rendering of
  44. fonts of any height, and of 4-16 pixels in width.  As far
  45. as I know, this is a first.  My own, and other fast text
  46. rendering routines only speed up rendering of 8 bit wide
  47. fonts.
  48.  
  49. This new Fast Text code is also somewhat easier to use then
  50. the previous two versions I released in 1978.
  51.  
  52. Oh, I went ahead, and added a font I created some time ago
  53. called WIDE.FONT.  Despite the name, WIDE.FONT is a
  54. skinnier 6 bit wide, 8 bit high Topaz style font.  It is a
  55. non-proportional font suitable for use with SetFont - using
  56. it effectively gives you more columns to work with, hence
  57. the name WIDE.FONT!
  58.  
  59. This new FastText() code is Copyrighted!  You must ask
  60. permission to utilize this code in any commercial, or
  61. shareware ventures.  Read the FastText.doc file for more
  62. information on how to contact me.
  63.  
  64. SHAR_EOF
  65. cat << \SHAR_EOF > Announcement
  66. This is my latest blitter based fast text rendering routines which are
  67. unique in that they speed up rendering of non-proportional fonts of any
  68. height, and from 4-16 pixels in width.    This stuff is written in assembly,
  69. and a test program written in Manx C is included to show off the speed
  70. difference between FastText(), and Text().  Source code is included - this
  71. file may be distributed freely, but permission is required to use these
  72. routines in commercial, and shareware products.
  73.  
  74. FastText Copyright 1988 by Darren M. Greenwald - Enjoy!
  75.  
  76. SHAR_EOF
  77. cat << \SHAR_EOF > 8.uu
  78.  
  79. begin 644 8
  80. M```#\P`````````!``````````````$-```#Z0```0UP`$YU```````````,^
  81. M`````!H/@``!````````````````````````````````````````````````J
  82. M```````````,`````!H``````\0`"`!#``8`!@`!```@?P```&X`2````JX`*
  83. M``````````")%"`$!!$``````'"''!/C/G'```@$''"/'./OG(OCLN(HG/'/%
  84. M'/HHHHHOG`#B`!`(`#`#`,"`H&```````$```````A&&@`')%'HJ!""-B```V
  85. M`(F(HC($(HHA!!`"(HG$HI$DHHB`DD(LHDHDHJHHHMHHD(`G`!`(`!`$@$``'
  86. M("```````$``````!!!+``'`/L)J"$!'"````IB!`E/(`HHA!"/A`KE$H(D$Z
  87. M((B`E$-NHDHDH"(HHG-A$$`M@`G+'%'$&E&`HB(O'+&M'O)(HHHOA!!```"`^
  88. M%'#&@$!/O@/@!/B"#)`O!''@`$``A*HG((G')OB`F$/KHG(G'"(HJB'"$"`H'
  89. M@`!-HK(N)&B`I"-HHDI&H$)(JE(I&!`@``"`/AF+`$!'"```",B$`O@HB(@@J
  90. M`"`!"+ODH(D$(HB(E$JIHD*E`B(E/G"$$!`@``'(H)/D)$B`N"*HHDI$G$)(6
  91. MJB(B!!!`````%/,I`""-B!`!$(B(HA(HB(A!!!/B`((DHI$D(HB(DDHHHD)DY
  92. MHB(G-MB(D`@@``)(HI($&$B`I"(HHG'$`DI'-E'$A!!```"`%"(F@!$``!`!0
  93. M('/OG#O'"'.!!`@$"'(O'./N'HOG,OHHG.'LG''B(HG/G`#@``&G'&G.!DG(&
  94. MHG(HG$!./#&B-HB/@A&``````````````"``````````````"```````````]
  95. M```````````@````````````/P``````/``'`````.!@``````,`````````E
  96. M``8`!@`&``P`!@`2``8`&``&`!X`!@`D``8`*@`&`#``!@`V``8`/``&`$(`.
  97. M!@!(``8`3@`&`%0`!@!:``8`8``&`&8`!@!L``8`<@`&`'@`!@!^``8`A``&J
  98. M`(H`!@"0``8`E@`&`)P`!@"B``8`J``&`*X`!@"T``8`N@`&`,``!@#&``8`Z
  99. MS``&`-(`!@#8``8`W@`&`.0`!@#J``8`\``&`/8`!@#\``8!`@`&`0@`!@$.A
  100. M``8!%``&`1H`!@$@``8!)@`&`2P`!@$R``8!.``&`3X`!@%$``8!2@`&`5``S
  101. M!@%6``8!7``&`6(`!@%H``8!;@`&`70`!@%Z``8!@``&`88`!@&,``8!D@`&/
  102. M`9@`!@&>``8!I``&`:H`!@&P``8!M@`&`;P`!@'"``8!R``&`<X`!@'4``8!@
  103. MV@`&`>``!@'F``8![``&`?(`!@'X``8!_@`&`@0`!@(*``8"$``&`A8`!@(<6
  104. M``8"(@`&`B@`!@(N``8"-``&`CH`!@)```8"0````^P````$``````````X`?
  105. 3``!$````7````&(````````#\CH`Q
  106. ``
  107. end
  108. size 1144
  109. SHAR_EOF
  110. cat << \SHAR_EOF > wide.font.uu
  111.  
  112. begin 644 wide.font
  113. M#P```5=)1$4O.```````````````````````````````````````````````@
  114. M`````````````````````````````````````````````````````````````
  115. M`````````````````````````````````````````````````````````````
  116. M`````````````````````````````````````````````````````````````
  117. M`````````````````````````````````````````````````````````````
  118. G````````````````````````````````````````````````"`!#+
  119. ``
  120. end
  121. size 264
  122. SHAR_EOF
  123. cat << \SHAR_EOF > FastText.asm
  124. *
  125. * Fast font Assembly sub-routines
  126. * Copyright 1988 by Darren M. Greenwald
  127. *
  128. * Rev. 3.0 9/27/88
  129. *
  130. * New blitter based routine to handle any size font
  131. *
  132. * This new routine relies on the brute force approach, and the blitter!
  133. * The font data is unpacked, and the masking, shifting, and target
  134. * addresses are pre-calculate for speed.
  135. *
  136. * This version of the fast text routines can render fonts of any height,
  137. * and of any size from 4-16 pixels wide.  Wider fonts, proportional fonts,
  138. * and styles are currently not supported.
  139. *
  140. * This routine is copyrighted, and freely distributable.  It may not be
  141. * used in any commercial product, shareware product, or commercial
  142. * publication  without permission.  It is permissible to release this file
  143. * as part of a public domain collection, or on a telecommunication service
  144. * as long as no "special charge" is made for this program;
  145. * "special charge" does not include standard charges for replication
  146. * of the media, or use of the system.
  147. *
  148. * The intent of the above should be clear - I did the work, and am giving
  149. * the code away for free.  While you may use it, you may not
  150. * profit from it.
  151. *
  152. * The previous fast text routines I released in 1987 were public domain
  153. * in every sense of the word.  In order to use these routines in a
  154. * commercial, or shareware venture, you must ask permission - at the most
  155. * I may ask in return that you include credit for the use of these
  156. * routines within your program's documentation, and/or free registration, or
  157. * a copy of the software you are developing.  In addition, I will provide
  158. * answers if you have any questions, and just maybe provide assistance
  159. * with modifying the routines to suit your needs.  All I ask is that you
  160. * ask!
  161. *
  162.  
  163.             XDEF     _InitFastText   ;Declare these labels visible to linker
  164.             XDEF     _FreeFastText
  165.             XDEF     _FastText
  166.  
  167.             XREF     _GfxBase
  168.             XREF     _LVOAllocMem
  169.             XREF     _LVOFreeMem
  170.             XREF     _LVOBltTemplate
  171.             XREF     _LVOText
  172.             XREF     _OwnBlitter
  173.             XREF     _DisownBlitter
  174.             XREF     _WaitBlit
  175.  
  176.             include  "SYS2:asm/exec/types.i"
  177.             include  "SYS2:asm/graphics/text.i"
  178.             include  "SYS2:asm/hardware/blit.i"
  179.             include  "SYS2:asm/hardware/custom.i"
  180.             include  "SYS2:asm/graphics/rastport.i"
  181.             CSEG
  182.  
  183. * ---------------------------------------------------------------------
  184. * Call this routine to free any memory allocated by InitFastText() 
  185. * below.
  186. * This is a safe routine - it can be called safely even if InitFastText()
  187. * fails.
  188. * ---------------------------------------------------------------------
  189. _FreeFastText:
  190.  
  191.             MOVE.L   FontData,D0       ;safety check for NULL ptr
  192.             BEQ      nodata
  193.             MOVEA.L  D0,A1             ;address of buffer to free
  194.             MOVE.L   FontSize,D0       ;size of buffer to free
  195.             MOVEA.L  $4,A6             ;ExecBase
  196.             JSR      _LVOFreeMem(A6)
  197.             CLR.L    FontData          ;set to NULL
  198.  
  199. nodata:
  200.  
  201.             MOVE.L   Imagebuf,D0
  202.             BEQ      nobuf             ;safety valve
  203.             MOVEA.L  D0,A1             ;address of buffer
  204.             MOVE.L   Imagesize,D0      ;size of working buffer
  205.             MOVEA.L  $4,A6
  206.             JSR      _LVOFreeMem(A6)
  207.             CLR.L    Imagebuf          ;set to NULL
  208.  
  209. nobuf:      RTS
  210.  
  211. * ---------------------------------------------------------------------
  212. * This routine does a few things for you.
  213. *
  214. * It checks to make sure the font size is within 4 bits wide, and 16
  215. * bits wide.  It also checks for PROP fonts.  Wider/thinner fonts, and
  216. * PROP fonts will cause this routine to fall through, and set up to
  217. * use Text() instead of the fast text routines.  This is transparent, so
  218. * you do not have to write additional code to handle anything if
  219. * the FastText() routine cannot be used.
  220. *
  221. * It allocates 2 chip ram buffers - one for the unpacked font data,
  222. * and the other for an image buffer to draw in.  The amount of space
  223. * required is calculated for you based on the font size per the pointer
  224. * to a TextFont structure which is passed via the stack.
  225. *
  226. * The font data is unpacked into words using an edge-to-edge model.
  227. * Extraneous bits are masked out, and the image data is left justified.
  228. *
  229. * The blitter masks, shifts, and destination addresses are pre-calcuated
  230. * for speed during rendering.
  231. *
  232. * An indirect function pointer is set-up based on the font width.  8 bit
  233. * wide fonts can be rendered faster then other fonts, so a special
  234. * blitter routine is devoted to handling 8 bit wide fonts.  Often this is
  235. * the most common font, so it makes sense to use this capability.
  236. *
  237. * ---------------------------------------------------------------------
  238.  
  239. font        EQU      04       ;stack offset
  240.  
  241. _InitFastText:
  242.  
  243.             MOVEA.L  font(SP),A2       ;address of a text font struct
  244.  
  245.             TST.L    tf_CharSpace(A2)  ;is this a prop font?
  246.             BNE      Initfailed
  247.  
  248.             CLR.L    D0
  249.  
  250.             MOVE.W   tf_XSize(A2),D0
  251.             MOVE.L   D0,XSize          ;save
  252.             CMP.W    #16,D0            ;check bounds of this
  253.             BHI      Initfailed
  254.  
  255.             MOVE.W   tf_YSize(A2),D0
  256.             MOVE.L   D0,YSize          ;save
  257.             CMP.W    #4,D0             ;check bounds of this
  258.             BLT      Initfailed
  259.  
  260.             MOVE.W   tf_Baseline(A2),Baseline
  261.  
  262. * allocate space for font imagery in unpacked word format - egads, this
  263. * uses a lot of memory, buts its the price to be paid I guess?
  264. *
  265.  
  266.             CLR.L    FontData          ;NULL by default
  267.             CLR.L    Imagebuf
  268.  
  269.             MULU     #512,D0           ;1 WORD per line * 256 chars
  270.             MOVE.L   D0,FontSize       ;save size of buffer
  271.             MOVE.L   #$10003,D1        ;MEMF_PUBLIC|MEMF_CHIP|MEMF_CLEAR
  272.             MOVEA.L  $4,A6
  273.             JSR      _LVOAllocMem(A6)  ;allocate space
  274.             TST.L    D0
  275.             BEQ      Initfailed        ;no memory for font data
  276.             MOVE.L   D0,FontData       ;save pointer
  277.  
  278. * allocate an image buffer for me to draw text in
  279.  
  280.             MOVE.L   YSize,D0
  281.             MULU     #128,D0           ;size of buffer calculated
  282.             MOVE.L   D0,Imagesize      ;save size
  283.             MOVEQ    #03,D1            ;MEMF_PUBLIC|MEMF_CHIP
  284.             MOVEA.L  $4,A6
  285.             JSR      _LVOAllocMem(A6)  ;allocate space
  286.             TST.L    D0
  287.             BEQ      NoImagebuf        ;no memory for font data
  288.             MOVE.L   D0,Imagebuf       ;save pointer
  289.  
  290. * unpack font data
  291.  
  292.             MOVEA.L  tf_CharLoc(A2),A0 ;location of offsets|width
  293.             MOVEA.L  tf_CharData(A2),A1
  294.             MOVEA.L  FontData,A3       ;where to put unpacked imagery
  295.  
  296.             CLR.L    D0
  297.             MOVE.B   tf_LoChar(A2),D0
  298.  
  299.             CLR.L    D1
  300.             MOVE.B   tf_HiChar(A2),D1
  301.  
  302.             SUB.B    D0,D1             ;total # of chars to unpack
  303.  
  304.             LSL.L    #1,D0             ;BYTE to WORD offset
  305.             ADDA.L   D0,A3             ;adjust pntr into image array now
  306.  
  307. dounpack:   MOVE.L   (A0)+,D0          ;fetch offset|width of each char
  308.  
  309.             CLR.L    D2
  310.             MOVE.W   D0,D2             ;width in D2
  311.  
  312.             SWAP     D0                ;pix offset in D0
  313.             CLR.L    D3
  314.             MOVE.W   D0,D3             ;word offset in D3
  315.  
  316.             AND.L    #$000F,D0
  317.             LSR.W    #4,D3             ;calc word offset
  318.             LSL.W    #1,D3
  319.  
  320.             CLR.L    D4                ;create mask
  321.             NOT.L    D4                ;all ones!
  322.             LSR.L    D2,D4             ;mask for this character
  323.             NOT.L    D4                ;invert mask
  324.  
  325.             MOVE.L   YSize,D5
  326.             SUBQ.W   #1,D5             ;-1 for DBF loop
  327.             CLR.L    D6
  328.  
  329. unpkfont:   MOVE.L   0(A1,D3.W),D7     ;create in D7
  330.  
  331.             LSL.L    D0,D7             ;left justify?
  332.             AND.L    D4,D7             ;mask lower bits
  333.             SWAP     D7                ;move to lower word
  334.             
  335.             MOVE.W   D7,0(A3,D6.L)     ;store
  336.  
  337.             ADD.W    tf_Modulo(A2),D3  ;adjust word offset
  338.             ADD.L    #512,D6
  339.  
  340.             DBF      D5,unpkfont
  341.  
  342.             ADDQ.L   #2,A3
  343.  
  344.             DBF      D1,dounpack
  345.  
  346. * set up arrays of pre-inited masks, shift values, and target addresses
  347.  
  348.             MOVE.W   #DEST+SRCB+SRCA+$FC,D7
  349.  
  350.             MOVE.L   XSize,D0
  351.             CMP.W    #08,D0            ;if equal to 8, use FASTEST mode!
  352.             BNE      docon0
  353.             MOVEQ    #00,D7            ;bltcon mask for bltcon1, or 0
  354.  
  355. docon0:
  356.  
  357.             MOVE.W   #255,D1           ;loop 256 times
  358.             MOVEQ    #00,D0            ;initial pixel offset
  359.  
  360.             MOVEA.L  #masks,A0
  361.             MOVEA.L  #shift,A1
  362.             MOVEA.L  #local,A2
  363.  
  364.             MOVEQ    #12,D5            ;shift value used later
  365.             MOVE.L   XSize,D6          ;used later
  366.  
  367. setup:      MOVE.L   D0,D2
  368.             MOVE.L   D2,D3
  369.  
  370.             LSR.W    #4,D2             ;calculate word offset
  371.             LSL.W    #1,D2             ; div by 16 * 2 for WORD offset
  372.  
  373.             AND.W    #$000F,D3         ;mask out all but pix offset
  374.  
  375.             MOVE.L   D2,D4
  376.             ADD.L    Imagebuf,D4       ;address to write this too
  377.             MOVE.L   D4,(A2)+          ;save address
  378.  
  379.             CLR.W    D4                ;create mask
  380.             NOT.W    D4                ;all ones!
  381.             LSR.W    D3,D4             ;mask for this character
  382.             NOT.W    D4                ;invert mask
  383.  
  384.             MOVE.W   D4,(A0)+          ;save mask
  385.  
  386.             LSL.W    D5,D3             ;shift for bltcon format
  387.             OR.W     D7,D3             ;depends of con0, or con1
  388.             MOVE.W   D3,(A1)+          ;save shift
  389.  
  390.             ADD.L    D6,D0
  391.             DBF      D1,setup
  392.  
  393. * determine maximum # of characters which can be drawn
  394.  
  395.             MOVE.L   XSize,D0
  396.             MOVE.L   #1008,D1
  397.             DIVU     D0,D1
  398.             MOVE.W   D1,Maxchars
  399.  
  400. * set-up blitter control functions based on font width
  401. * optimize for 8 bit wide fonts!
  402.  
  403.             CMP.W    #08,D0            ;if equal to 8, use FASTER mode!
  404.             BEQ      faster
  405.  
  406. slower:     MOVE.L   #Bltslow,OutPut
  407.             MOVEQ    #2,D0             ;width
  408.             BRA      setsize
  409.  
  410. faster:     MOVE.L   #Bltfast,OutPut
  411.             MOVEQ    #1,D0             ;width
  412.  
  413. setsize:    MOVE.L   YSize,D1          ;height
  414.             LSL.W    #6,D1             ;per blitter's delight
  415.             OR.W     D1,D0
  416.             MOVE.L   D0,blitsize
  417.  
  418.             RTS                        ;return TRUE
  419.  
  420.  
  421. * some error, return false
  422.  
  423. NoImagebuf: JSR      _FreeFastText     ;release alloced memory
  424.  
  425. * indicates regular system Text() may be used via these calls
  426.  
  427. Initfailed: CLR.L    OutPut            ;default to calling Text()
  428.             MOVEQ    #00,D0            ;return FALSE
  429.             RTS
  430.  
  431.  
  432. * ---------------------------------------------------------------------
  433. * Routines to render the line via the blitter!
  434. *
  435. * The blitter routines vary somewhat to optimize for speed!  8 bit wide
  436. * fonts are drawn much faster then other width fonts, but all fonts
  437. * are drawn much faster then Text()!  This makes sense to do this since
  438. * 8 bit wide fonts are the most common, and because I can make use of
  439. * some special blitter capabilities to speed the process along!
  440. * ---------------------------------------------------------------------
  441.  
  442.  
  443. rp          EQU      0004        ;stack offsets
  444. txbptr      EQU      rp+4
  445. count       EQU      txbptr+4
  446.  
  447. _FastText:  TST.L    OutPut
  448.             BEQ      CallText    ;if InitFastText() failed!
  449.  
  450.             MOVE.L   count(SP),D3
  451.             BEQ      Noway       ;why would you put a 0 for # of chars?
  452.             CMP.W    Maxchars,D3
  453.             BLS      getblitter
  454.             MOVE.W   Maxchars,D3 ;prevent overflow
  455.  
  456. * ok, I need that blitter for me only!
  457.  
  458. getblitter: SUBQ.W   #1,D3
  459.             JSR      _OwnBlitter
  460.             JSR      _WaitBlit
  461.  
  462. * set-up globals first
  463.  
  464.             MOVEA.L  txbptr(SP),A0
  465.             MOVEM.L  group,D4-D7/A1-A3
  466.  
  467. * call appropriate routine
  468.  
  469.             MOVEA.L  OutPut,A6
  470.             JSR      (A6)
  471.  
  472. * free blitter for someone else
  473.  
  474.             JSR      _DisownBlitter
  475.  
  476. * now blast this into the rastport!
  477.  
  478.             MOVEA.L  Imagebuf,A0       ;address of bitplane
  479.             MOVEQ    #00,D0            ;no offset
  480.             MOVE.L   #128,D1           ;src modulo
  481.             MOVEA.L  rp(SP),A1         ;rastport
  482.             CLR.L    D2
  483.             MOVE.W   rp_cp_x(A1),D2    ;x dest
  484.             ADD.W    D4,rp_cp_x(A1)    ;modify Move() position
  485.             CLR.L    D3
  486.             MOVE.W   rp_cp_y(A1),D3    ;dest y
  487.             SUB.W    Baseline,D3       ;- baseline of font
  488.             MOVE.L   YSize,D5          ;y size
  489.             MOVEA.L  _GfxBase,A6
  490.             JSR      _LVOBltTemplate(A6)
  491. Noway:      RTS
  492.  
  493.  
  494. * If InitFastText() failed, Text() may still be called via the
  495. * FastText() function.
  496. *
  497. * This makes use in a system which must use any size font easier to program.
  498. *
  499. CallText:   MOVEA.L  rp(SP),A1
  500.             MOVEA.L  txbptr(SP),A0
  501.             MOVE.L   count(SP),D0
  502.             MOVEA.L  _GfxBase,A6
  503.             JSR      _LVOText(A6)
  504.             RTS
  505.  
  506. * --------------------------------------------------
  507. * This is the faster logic for an 8 bit wide fonts!
  508. * --------------------------------------------------
  509. Bltfast:    MOVEA.L  #$dff000,A6       ;address of custom chips
  510.  
  511. * once set, these blitter registers dont change
  512.  
  513.             MOVE.W   #DEST+SRCB+SRCA+$FC,bltcon0(A6)
  514.             MOVE.W   #$FFFF,bltalwm(A6)   ;no last word mask
  515.             MOVE.W   #126,bltdmod(A6)
  516.             MOVE.W   #126,bltamod(A6)
  517.             MOVE.W   #510,bltbmod(A6)
  518.  
  519. * do as much set-up as possible while last blit is busy
  520.  
  521. blit8:      CLR.L    D0
  522.             MOVE.B   (A0)+,D0
  523.             BEQ      blt8done          ;terminate if NULL found
  524.  
  525.             LSL.W    #1,D0             ;cast to WORD offset
  526.             ADD.L    D5,D0             ;ready with pointer!
  527.  
  528.             ADD.L    D6,D4             ;add to width
  529.  
  530. Wait8:      BTST     #6,dmaconr(A6)    ;wait for last blit to complete
  531.             BNE      Wait8
  532.  
  533. * these blitter register change for each blit
  534.  
  535.             MOVE.L   D0,bltbpt(A6)     ;b src
  536.             MOVE.L   (A3),bltdpt(A6)   ;d src pntr
  537.             MOVE.L   (A3)+,bltapt(A6)  ;a src pntr
  538.             MOVE.W   (A1)+,bltafwm(A6) ;first word mask           
  539.             MOVE.W   (A2)+,bltcon1(A6) ;shift value for b
  540.  
  541.             MOVE.W   D7,bltsize(A6)    ;trigger blit
  542.             DBF      D3,blit8          ;char counter
  543.  
  544. blt8done:   RTS
  545.  
  546. * --------------------------------------------------
  547. * This is the slower mode for odd width fonts!
  548. * --------------------------------------------------
  549. Bltslow:    MOVEA.L  #$dff000,A6       ;address of custom chips
  550.             MOVEQ    #00,D1            ;address of destination here
  551.  
  552. * these registers dont change once set
  553.  
  554.             CLR.W    bltalwm(A6)       ;last word mask
  555.             CLR.W    bltcon1(A6)       ;no special modes
  556.             MOVE.W   #124,bltbmod(A6)  ;modulos
  557.             MOVE.W   #124,bltdmod(A6)
  558.  
  559. * this bit clears the image buffer as needed - speed optimized
  560. * thinner fonts will be drawn faster due to less hits
  561. * a hit is TRUE whenever the font imagery rolls over into the next word
  562.  
  563. doblits:    MOVE.W   (A1)+,D0
  564.             MOVE.L   (A3)+,D2
  565.             CMP.L    D2,D1
  566.             BEQ      dochars           ;working on same word
  567.  
  568. Waitlast:   BTST     #6,dmaconr(A6)    ;wait if needed
  569.             BNE      Waitlast
  570.  
  571.             MOVE.L   D2,D1             ;save for next time around
  572.  
  573.             MOVE.W   #124,bltamod(A6)
  574.             MOVE.W   D0,bltafwm(A6)
  575.             MOVE.L   D2,bltdpt(A6)     ;d src pntr
  576.             MOVE.L   D2,bltapt(A6)     ;a src pntr
  577.             MOVE.W   #DEST+SRCA+$F0,bltcon0(A6) ;d=a
  578.             MOVE.W   D7,bltsize(A6)    ;trigger blitter clear
  579.  
  580. * setup while last blit is busy
  581.  
  582. dochars:    CLR.L    D0
  583.             MOVE.B   (A0)+,D0
  584.             BEQ      bltodddone        ;terminate if NULL found
  585.  
  586.             LSL.W    #1,D0             ;cast to WORD offset
  587.             ADD.L    D5,D0             ;ready with pointer!
  588.  
  589.             ADD.L    D6,D4             ;add to width
  590.  
  591. Waitpack:   BTST     #6,dmaconr(A6)    ;wait for image packing
  592.             BNE      Waitpack
  593.  
  594. * set up blitter for character image move
  595.  
  596.             MOVE.W   #508,bltamod(A6)
  597.             MOVE.W   #$FFFF,bltafwm(A6)
  598.             MOVE.L   D0,bltapt(A6)     ;a src
  599.             MOVE.L   D2,bltbpt(A6)     ;b src pntr
  600.             MOVE.L   D2,bltdpt(A6)     ;d src pntr
  601.             MOVE.W   (A2)+,bltcon0(A6) ;shift value for a
  602.             MOVE.W   D7,bltsize(A6)    ;trigger blit
  603.  
  604.             DBF      D3,doblits        ;checks count
  605.  
  606. bltodddone: RTS
  607.  
  608.             RTS
  609.  
  610.  
  611.             DSEG
  612. * global variables I use - private!
  613.  
  614. Imagebuf:   dc.l     0     ;address of image buffer - part of above struct
  615. Imagesize:  ds.l     1     ;size of working buffer
  616.  
  617. FontSize:   ds.l     1     ;size of font data buffer
  618.  
  619. YSize:      ds.l     1     ;size of font height
  620.  
  621. Maxchars:   ds.w     1     ;Max chars which can be drawn at one time
  622.  
  623. Baseline:   ds.w     1     ;baseline of font
  624.  
  625. OutPut:     dc.l     0     ;address of function to call or NULL for Text()
  626.  
  627. masks:      ds.w     256   ;256 words for masks
  628. shift:      ds.w     256   ;256 shift values
  629. local:      ds.l     256   ;256 pointers to target location
  630.  
  631. * these are grouped for a good reason - the MOVEM instruction is used
  632. * by the rendering routines for efficiency - DONT play with the order
  633. * of these unless you know what you are doing.
  634.  
  635. group:      dc.l     0     ;0 to init width of line register
  636. FontData:   dc.l     0     ;address of font data
  637. XSize:      dc.l     0     ;size of font width
  638. blitsize:   dc.l     0     ;blit size value
  639.             dc.l     masks ;address of arrays
  640.             dc.l     shift
  641.             dc.l     local
  642.  
  643.  
  644.             END
  645.  
  646. SHAR_EOF
  647. cat << \SHAR_EOF > FastText.doc
  648. FastText revision 3.0 Copyright 1988 by Darren M. Greenwald
  649.  
  650. FastText is a copyrighted program.  It may be distributed freely, but it
  651. may NOT be sold/included in any way in any commercial, or shareware
  652. ventures without permission from the author.  It may be distributed in
  653. other public domain works so long as a notice of credit appears in the
  654. documentation.
  655.  
  656. FastText may be distributed as part of a public domain collection, and
  657. posted on telecommunication services so long as no additional charge is
  658. made above, and beyond the normal, and reasonable fees charged for
  659. the media, or use of system time.
  660.  
  661. If you would like permission to use this program in a commercial, or
  662. shareware venture, I can be contacted via the following methods:
  663.  
  664. On GEnie:               Send E-MAIL to DMG
  665. On Cute (714) 532-5698: Post a message in any forum to Darren Greenwald
  666. At Home:                (714) 545-6458
  667.  
  668. Including FastText in your programs -
  669.  
  670. FastText is written in assembly using the Manx Assembler.  Any changes
  671. needed to assemble this file with other assemblers is left up to you. 
  672. You need then only link the resulting object file with your code, and
  673. replace all calls too Text() with FastText().  In addition you must call the
  674. InitFastText() routine before calling FastText(), and finally call
  675. FreeFastText() as part of your cleanup/exit routine(s).  See the included
  676. FastText demo (Ftest.c) for an example of how easy this is to use.
  677.  
  678. In "C" format, the calls are defined like so:
  679.  
  680. InitFastText
  681. ------------
  682.  
  683. success=InitFastText(Font)
  684.  
  685. Inputs: Font - pointer to a TextFont structure
  686.  
  687. Return: TRUE, or FALSE
  688.  
  689. Description:
  690.  
  691. This routine does a number of things for you.  It checks to make sure that
  692. the font is a non-proportional font; it also checks to make sure the font
  693. is no less then 4 bits wide, but no more then 16 bits.  In any other case
  694. this routine returns FALSE.  Should this routine fail, you need not concern
  695. yourself too much.  In this case all calls to FastText() are automatically
  696. routed to call Text() instead.
  697.  
  698. Two CHIP RAM buffers are allocated based on the fonts height.  Fonts can be
  699. any height, but keep in mind that taller fonts use more memory.  One chip
  700. ram buffer is allocated for use as a buffer to draw the text imagery in, and
  701. the other is used to store the unpacked font data.
  702.  
  703. The font image data buffer requires 512 bytes * the font height.
  704.  
  705. The drawing buffer requires 128 bytes * the font height.
  706.  
  707. If this seems like a lot of memory, this is the trade off you make for the
  708. faster text rendering.  If the memory cannot be allocated, this routine
  709. will return FALSE, and all calls to FastText() are routed to call Text()
  710. instead.
  711.  
  712. Finally this routine upacks the font data, sets up the masks, blitter shift
  713. values, and some pointers to the image buffer.  Precalculating this
  714. stuff means that these calculations do not have to be done each time a line
  715. of text is rendered.
  716.  
  717. A special faster blitter routine is used for 8 bit wide fonts because 1.)
  718. Due to the way the blitter handles shifting it is possible to draw 8 bit
  719. wide fonts faster, and 2.) This works out well since 8 bit wide fonts are
  720. commonly used as the system font.
  721.  
  722. This routine should be called as part of your programs initialization
  723. procedures - it is your option to check for a return value since even if
  724. this fails, all calls to FastText() will automatically call Text() instead.
  725. This routine executes lickety-split; you won't have to wait "a moment" for
  726. the unpacking, and set-up to complete.
  727.  
  728. FastText
  729. --------
  730.  
  731. FastText(p,string,length)
  732.  
  733. Inputs: rp       - pointer to a rastport structure
  734.         string   - pointer to a string
  735.         length   - length of string to draw
  736.  
  737. Return: None
  738.  
  739. Description:
  740.  
  741. This call is very similar to Text().  It uses the exact same parameters
  742. as Text(), and behaves in a very similar manner.  You can set drawing
  743. colors (via SetAPen(), SetBPen()), drawing modes, etc.  The text position
  744. is set via the Move() function just like Text().
  745.  
  746. The X drawing position in the rastport is automatically incremented by the
  747. length (in pixels) of the string of text.
  748.  
  749. There are also some significant differences (speed of rendering included)!
  750.  
  751. Unlike Text() which draws a special image for non-defined characters in a
  752. font, FastText() draws undefined characters as blank spaces.  This could be
  753. changed if it causes anyone any problems.  I prefer it this way, but
  754. perhaps you may not?
  755.  
  756. FastText() does not currently support any font styles (e.g., bold,
  757. underline, italics).  This may be changed in the future.
  758.  
  759. The REVPATH flag is ignored.
  760.  
  761. FastText() treats NULL's as End of Line characters regardless of the length
  762. of string parameter.  This behavior can be changed if it causes anyone any
  763. problems.  I like it this way, but you may not.  Yes, this was intentional
  764. since it means I can call FastText(), and set the count to some large
  765. number rather then having to calculate the length of each string.  Text()
  766. on the other hand is terminated only by the length parameter, and will
  767. print NULL's as a non-printable character (usually a BOXY looking image).
  768.  
  769.  
  770. FreeFastText
  771. ------------
  772.  
  773. FreeFastText()
  774.  
  775. Inputs: None
  776.  
  777. Return: None
  778.  
  779. Description:
  780.  
  781. Frees memory allocated by InitFastText().  This routine can be called
  782. safely even if InitFastText() failed - in other words, it won't try to free
  783. memory which was never allocated.
  784.  
  785. ----------------------------------------------------------------------
  786.  
  787. Other notes:
  788.  
  789. It is very likely that this code is less then perfect.  Let the bug reports
  790. roll in!  Let me know, and I'll try to fix it ASAP.  Also hopefully I can
  791. further optimize the speed of the rendering routines.  In the future this
  792. whole thing may change anyway so that multiple fonts can be opened at the
  793. same time.SHAR_EOF
  794. cat << \SHAR_EOF > Ftest.c
  795. /*
  796.  * FastText() text demo by Darren M. Greenwald
  797.  * Copyright 1987 - FastText() REV 3.0
  798.  *
  799.  * "C" example of use.
  800.  * 
  801.  * You MUST assemble, and link in the FastText file in order for this to
  802.  * work!!!
  803.  * 
  804.  * Note that all work was done using Manx 3.6
  805.  * I leave it up to you to make adjustments as needed to work with your
  806.  * compiler/assembler.
  807.  *
  808.  * TURN OFF any text speed up programs if you really want to test this
  809.  * program right.  Programs such BLITZFONTS, and MicroSmith's FastFonts
  810.  * only speed up 8 bit wide fonts.  These routines allow you to gain
  811.  * a significant speed up for all size fonts, and the most speed up for
  812.  * 8 bit wide fonts.  Font widths other then 8 bits wide will vary in
  813.  * speed.  Thinner fonts will be drawn more quickly then wider fonts, but
  814.  * you can rest assured that the FastText() routines draw text faster then
  815.  * Text() - generally MUCH faster.
  816.  *
  817.  * If the font cannot be drawn faster (e.g., too wide, too thin, PROP
  818.  * font), then Text() is automatically called.
  819.  * 
  820.  */
  821.  
  822. #include <exec/types.h>
  823. #include <intuition/intuition.h>
  824. #include <exec/memory.h>
  825.  
  826. #define REV 0L
  827. #define SIZE 640L
  828.  
  829. struct IntuitionBase *IntuitionBase = NULL;
  830. struct GfxBase *GfxBase = NULL;
  831. struct Window *Window = NULL;
  832. struct RastPort *rp;
  833. struct Window *OpenWindow();
  834. void *OpenLibrary();
  835.  
  836. struct NewWindow NewWindow =
  837.    { 0,0,640,200,0,1,
  838.      CLOSEWINDOW,ACTIVATE|BORDERLESS|WINDOWDEPTH|WINDOWCLOSE|SMART_REFRESH,
  839.      NULL,NULL,
  840.      (UBYTE *)"FastText Demo Rev 3.0 - Close me!",
  841.      NULL,NULL,0,0,0,0,WBENCHSCREEN
  842.    };
  843.  
  844. void Cleanup();
  845.  
  846.  
  847. void main()
  848. {
  849.  
  850. ULONG MaxRows,fonthght,pixrow,i,j;
  851.  
  852.    IntuitionBase = (struct IntuitionBase *)
  853.       OpenLibrary("intuition.library",REV);
  854.    if(IntuitionBase == NULL) Cleanup();
  855.  
  856.    GfxBase = (struct GfxBase *)
  857.       OpenLibrary("graphics.library",REV);
  858.    if(GfxBase == NULL) Cleanup();
  859.  
  860.    Window = (struct Window *)
  861.       OpenWindow(&NewWindow);
  862.    if(Window == NULL) Cleanup();
  863.  
  864.    rp = Window->RPort;
  865.  
  866.  
  867. /*
  868.  * Wait till the close us down cause we are to lazy to mess with gadgets,
  869.  * or menus!
  870.  */
  871.  
  872.    Wait(1L<<Window->UserPort->mp_SigBit);
  873.  
  874.    SetAPen(rp,1L);
  875.    SetBPen(rp,0L);
  876.  
  877.    InitFastText(rp->Font); /* You could check for a TRUE/FALSE return */
  878.    
  879.       pixrow=32L;
  880.  
  881.       fonthght=(ULONG)rp->Font->tf_YSize;
  882.       MaxRows=(Window->Height-pixrow)/fonthght;
  883.  
  884.       SetWindowTitles(Window,"Drawing via Text()",NULL);
  885.  
  886.       for(i=1;i<MaxRows;i++)  /* do maximum # of times possible */
  887.       {
  888.          for(j=1;j<200;j++)   /* redraw line 300 times per row */
  889.          {
  890.             Move(rp,j+4L,pixrow);
  891.             Text(rp," This is 36 characters of SLOW text!",36L);
  892.          }
  893.          pixrow+=fonthght;
  894.       }
  895.  
  896. dox:  pixrow=32L;
  897.  
  898.       SetWindowTitles(Window,"Drawing via FastText()",NULL);
  899.  
  900.       for(i=1;i<MaxRows;i++)  /* do maximum # of times possible */
  901.       {
  902.          for(j=1;j<200;j++)   /* redraw line 300 times per row */
  903.          {
  904.             Move(rp,j+4L,pixrow);
  905.             FastText(rp," This is 36 characters of FAST text!",36L);
  906.          }
  907.          pixrow+=fonthght;
  908.       }
  909.  
  910.  
  911.    Cleanup();
  912. }
  913.  
  914. void Cleanup()
  915. {
  916.    FreeFastText();
  917.  
  918.    if(Window)           CloseWindow(Window);
  919.  
  920.    if(GfxBase)          CloseLibrary(GfxBase);
  921.    if(IntuitionBase)    CloseLibrary(IntuitionBase);
  922.  
  923.    exit(0L);
  924. }
  925.  
  926.  
  927. SHAR_EOF
  928. #    End of shell archive
  929. exit 0
  930. -- 
  931. Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
  932. Have five nice days.
  933.